<?php
namespace App\Http\Middleware;
use App\Exceptions\InternalException;
use App\Exceptions\InvalidTokenException;
use App\Exceptions\TokenInvalidException;
use App\Services\TokenService;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;

/**
 * @Author: dxf
 * @Date: 2021-07-19
 * @Time: 14:28
 */

/**
 * 客户端header头验证
 */
class ClientMiddleware{

    /**
     * Handle an incoming request.
     *
     * @param Request $request
     * @param \Closure $next
     * @return mixed
     * @throws TokenInvalidException
     */
    public function handle($request, Closure $next)
    {
        $client = $request->header('client');

        if(!in_array($client, config('custom.client_type', []))){
            throw new TokenInvalidException('无效Token');
        }

        return $next($request);
    }

}
